const baseurl = "https://api-hmugo-web.itheima.net/api/public/v1"
const request = function (url,data,methods,myheader) {
  // 不仅可以创建默认的header还可以接收新的header
  let header={...myheader}
  if(url.includes("/my/")){
    header["Authorization"]=wx.getStorageSync('token')
  }
  wx.showLoading({
    title: "加载中",
    mask: true
  });
  return new Promise((resolve, reject) => {
    wx.request({
        url: baseurl + url,
        data,
        method:methods || "GET",
        header,
        success: (res) => {
          resolve(res)
          wx.hideLoading({
            success: (res) => {
              console.log("获取成功");
            },
          })
        },
        fail:(result)=>{
          reject(result)
          wx.hideLoading({
            success: (res) => {
              console.log("获取失败");
            },
          })
        }
      })
  })
}
export default request